package com.example.neusoft.yuejian_12.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.neusoft.yuejian_12.Activity.ClubDetailActivity;
import com.example.neusoft.yuejian_12.Activity.SignInfoActivity;
import com.example.neusoft.yuejian_12.JavaBean.UserOrder;
import com.example.neusoft.yuejian_12.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 晓真 on 2017/10/24.
 */

public class UserComOrderListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;//承载上下文
    private List<UserOrder> mDataList;//动态数组承载数据使用 数据存储
    private LayoutInflater mLayoutInflater; //准备布局

    public UserComOrderListAdapter(Context mContext, List<UserOrder> mDataList){
        this.mContext=mContext;
        this.mDataList=mDataList;
        mLayoutInflater=LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v=mLayoutInflater.from(parent.getContext()).inflate(R.layout.user_allorder_item,parent,false);
        return new UserComOrderListAdapter.ViewHolder(v);
    }

    //将数据绑定到控件
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final  UserOrder entity= mDataList.get(position);
        if (null==entity)
            return;
        UserComOrderListAdapter.ViewHolder viewHolder= (UserComOrderListAdapter.ViewHolder) holder;
        viewHolder.orderid.setText("订单编号："+entity.getId());
//        viewHolder.state.setText(entity.getSignid());
        if(entity.getVstate().equals("0")){
            viewHolder.state.setText("未参加");
        }
        else {
            viewHolder.state.setText("已完成");
        }
        viewHolder.act_name.setText(entity.getName());
        viewHolder.price.setText(entity.getPrice());
        viewHolder.time.setText(entity.getUpdate_time());
        viewHolder.allprice.setText(entity.getPay());
        if(!entity.getThumb().isEmpty()) {
            Picasso.with(mContext).load("http://172.24.10.175/workout/Uploads/"+entity.getThumb()).into(viewHolder.pic);
        } else {
            viewHolder.pic.setImageResource(R.drawable.qya);
        }
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(mContext,SignInfoActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("id",entity.getId());
                intent.putExtra("idtype",entity.getType());
                intent.putExtra("title",entity.getName());
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    //找到控件，将其初始化
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView pic;
        TextView orderid,state, act_name, price, time, allprice;
        public ViewHolder(View itemView) {
            super(itemView);
            pic = (ImageView) itemView.findViewById(R.id.allorder_pic);
            orderid = (TextView) itemView.findViewById(R.id.allorder_id);
            state = (TextView) itemView.findViewById(R.id.allorder_state);
            act_name = (TextView) itemView.findViewById(R.id.allorder_act_name);
            price = (TextView) itemView.findViewById(R.id.allorder_act_price);
            time = (TextView) itemView.findViewById(R.id.allorder_order_time);
            allprice = (TextView) itemView.findViewById(R.id.allorder_allprice);
        }
    }
}

